﻿Imports System.Collections.Generic
Imports System.Data
Imports CondorTravel.BC
Imports CondorTravel.BE
Imports CondorTravelUTIL.DL

Public Class BuscarProveedor
    Inherits PaginaBase

    Dim itemgridview As GridViewRow
    Dim casilla As System.Web.UI.WebControls.CheckBox

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Load


    End Sub


    Private Sub ListarProveedores()

        Dim objProveedorBE As New ProveedorBE
        Dim objProveedorBC As New ProveedorBC
        Dim bExito As Boolean = False
        Dim sMensaje As String = String.Empty

        objProveedorBE.RazonSocial = txtRazonSocial.Text.Trim
        objProveedorBE.Ruc = txtRUC.Text.Trim

        dgSolicitudServicio.DataSource = objProveedorBC.ProveedorListar(objProveedorBE, bExito, sMensaje)
        dgSolicitudServicio.DataBind()

        If dgSolicitudServicio.Rows.Count <= 0 Then
            dgSolicitudServicio.Visible = False
            lblError.Visible = True
        Else
            dgSolicitudServicio.Visible = True
            lblError.Visible = False
        End If
    End Sub


    Protected Sub btnConsultar_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnConsultar.Click
        ListarProveedores()
    End Sub

    Protected Sub btnSeleccionar_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnSeleccionar.Click

        Dim dt As New DataTable
        Dim scodigo As String = String.Empty
        Dim sRazonSocial As String = String.Empty
        Dim sRuc As String = String.Empty
        Dim scadena As String


        Dim iContador As Integer
        For Each Me.itemgridview In dgSolicitudServicio.Rows
            casilla = itemgridview.FindControl("chkSeleccionar")
            If casilla.Checked = True Then
                iContador = iContador + 1
            End If
        Next

        If iContador > 1 Then
            Alerta("Solo se permite seleccionar un registro.", False, String.Empty)
            Exit Sub
        End If



        For Each Me.itemgridview In dgSolicitudServicio.Rows
            casilla = itemgridview.FindControl("chkSeleccionar")

            If casilla.Checked = True Then
                scodigo = CType(itemgridview.FindControl("lblcodigo"), Label).Text
                sRazonSocial = CType(itemgridview.FindControl("lblRazonSocial"), Label).Text
                sRuc = CType(itemgridview.FindControl("lblRuc"), Label).Text

            End If

        Next

        If scodigo = String.Empty Then
            Exit Sub
        End If

        scadena = scodigo

        'Response.Write("<script language=Javascript>window.opener.location.reload();</script>")
        Response.Write("<script language=Javascript>window.returnValue = " & scadena & ";</script>")
        Response.Write("<script language=Javascript>window.close();</script>")
        Session("BPCodigoProveedor") = scodigo
        Session("BPRazonSocialProveedor") = sRazonSocial
        Session("BPRUCProveedor") = sRuc

    End Sub

    Protected Sub btnSalir_Click(ByVal sender As Object, ByVal e As EventArgs) Handles btnSalir.Click
        Response.Write("<script language=Javascript>window.close();</script>")
    End Sub
End Class